package cn.lanqiao.facelogin.utils;




import cn.lanqiao.facelogin.domain.LoginData;
import sun.misc.BASE64Decoder;

import java.io.File;
import java.io.FileOutputStream;

public class BASE64SaveToLocalImage {

    public static boolean m1(String base64, Object faceToken) throws Exception {
//        String substring = base64.substring(22);
        String base64String = base64.replace(" ", "+");
        BASE64Decoder decoder = new BASE64Decoder();
        byte[] bytes1 = decoder.decodeBuffer(base64String);
        String imageUrl = faceToken+".png";
        String path = "src/main/resources/static/img";
        for (int i = 0; i < bytes1.length; i++) {
            if (bytes1[i] < 0) {
                bytes1[i] += 256;
            }
        }
        File file = new File(path, imageUrl);
        if (!file.exists()) {
            file.createNewFile();
        }
        FileOutputStream out = new FileOutputStream(file);
        out.write(bytes1);
        out.flush();
        out.close();
        return true;
    }

}